using Pinwheel.LSerialize;

namespace Pinwheel.Kernel
{
    public interface INetPacket
    {
    }
    
    [LSerializable]
    public partial struct NetPacket : INetPacket
    {
        [LSerializeInclude] private ulong m_Header;
        [LSerializeInclude] private string m_Service;
        [LSerializeInclude] private byte[] m_Data;
        
        [LSerializeIgnore] public byte Type => (byte) ((m_Header >> 56) & 0xFF);
        [LSerializeIgnore] public byte Tag => (byte) ((m_Header >> 48) & 0xFF);
        [LSerializeIgnore] public int Session => (int) (m_Header & 0xFFFFFFFF);
        [LSerializeIgnore] public string Service => m_Service;
        [LSerializeIgnore] public byte[] Data => m_Data;
        
        public void SetType(byte type)
        {
            m_Header = (m_Header & 0x00FFFFFFFFFFFFFF) | ((ulong)type << 56);
        }
        
        public void SetTag(byte tag)
        {
            m_Header = (m_Header & 0xFF00FFFFFFFFFFFF) | ((ulong)tag << 48);
        }
        
        public void SetSession(int session)
        {
            m_Header = (m_Header & 0xFFFFFFFF00000000) | (uint) session;
        }
        
        public void SetName(string name)
        {
            m_Service = name;
        }
        
        public void SetData(byte[] data)
        {
            m_Data = data;
        }
    }
}